<!--学生查看活动报名记录列表-->
<style>
	.kechengxiangqing {
		margin-bottom: 0;
		border-bottom: 0;
	}
	
	.kechengxiangqing tr>th {
		border-bottom: 0;
	}
	
	.tr_class {
		cursor: pointer;
	}
</style>

<br/>

<h3>活动报名记录</h3>

<br/>

<table class="table table-striped table-bordered table-hover text-center table-test">
	<thead>

	</thead>
	<tbody>

	</tbody>
</table>

<nav aria-label="...">
	<ul class="pager">
		<li>
			<a href="#" id="pre">上一页</a>
		</li>
		<li>
			<a href="#" id="top">首页</a>
		</li>
		<li>第<span class="num">1</span>页</li>
		<li>
			<a href="#" id="end">尾页</a>
		</li>
		<li>
			<a href="#" id="next">下一页</a>
		</li>
	</ul>
</nav>

<script>
	function fenye(data) {
		if(data.status == 0) {
			$.session.set("prePageNum", data.page.prePageNum);
			$.session.set("nextPageNum", data.page.nextPageNum);
			$.session.set("totalPageNum", data.page.totalPageNum);
			$('.num').html(data.page.pageNum);
			$('table').html("");

			console.log(data);
			var list = data.page.list;

			var $tr = $('<tr></tr>');
			var top = `
	            <td><b>活动标题</b></td>
	            <td><b>报名时间</b></td>
	            <td><b>审核状态</b></td>
            `;

			$tr.append(top);
			$('table').append($tr);

			for(var i = 0; i < list.length; i++) {
				var $tr = $(`<tr class="tr_class" id="tr_` + list[i].aid + `" value=` + list[i].aid + `></tr>`);

				var value = "";
				if(list[i].situation == 0) {
					value = "审核中";
				} else if(list[i].situation == 1) {
					value = "报名成功";
				} else if(list[i].situation == -1) {
					value = "报名失败";
				}

				var $td = $(`<td>` + list[i].title + `</td>
                <td>` + timeStamp2String(list[i].addTime) + `</td>
                <td>` + value + `</td>`);

				$tr.append($td)

				$('table').append($tr)

				var tr_id = "#tr_" + list[i].aid;

				$(tr_id).click(function() {
					$.session.set('aid', $(this).attr("value"));
					$('.center').html('');
					$('.center').load('./lookactivity.html');
				})
			}
		}
	}

	$.ajax({
		xhrFields: {
			withCredentials: true
		},
		type: "GET",
		dataType: 'json',
		url: getFullURL("user/query-activity"),
		data: {
			"pageNum": 1,
			"pageSize": 15
		},
		success: function(data) {
			fenye(data);
		},
		error: function(err) {
			alert("请求异常，请重新登录！", function() {
				$(location).attr('href', './login.html');
			})
		}
	})

	$("#top").click(function() {
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: "GET",
			url: getFullURL("user/query-activity"),
			data: {
				pageNum: 1,
				pageSize: 15
			},
			success: function(data) {
				fenye(data);
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	})

	$("#end").click(function() {
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: "GET",
			url: getFullURL("user/query-activity"),
			data: {
				pageNum: $.session.get("totalPageNum"),
				pageSize: 15
			},
			success: function(data) {
				fenye(data);
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	})

	$("#pre").click(function() {
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: "GET",
			url: getFullURL("user/query-activity"),
			data: {
				pageNum: $.session.get("prePageNum"),
				pageSize: 15
			},
			success: function(data) {
				fenye(data);
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	})

	$("#next").click(function() {
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: "GET",
			url: getFullURL("user/query-activity"),
			data: {
				pageNum: $.session.get("nextPageNum"),
				pageSize: 15
			},
			success: function(data) {
				fenye(data);
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	})

	function timeStamp2String(time) {
		var datetime = new Date();
		datetime.setTime(time);
		var year = datetime.getFullYear();
		var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
		var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
		var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
		var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
		var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
		return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
	}
</script>